/**
 *
 */
package weibo4j.http;

import com.google.appengine.api.images.Image;
import com.google.appengine.api.images.ImagesService;
import com.google.appengine.api.images.ImagesServiceFactory;
import com.google.appengine.api.images.Transform;

/**
 * 临时存储上传图片的内容，格式，文件信息等
 * 
 * @author zhulei
 * 
 */
public class ImageItem {
	private byte[] content;
	private String name;
	private String contentType;

	public ImageItem(String name, byte[] content) throws Exception {

		ImagesService imagesService = ImagesServiceFactory.getImagesService();
		Image oldImage = ImagesServiceFactory.makeImage(content);
		Transform transform = ImagesServiceFactory.makeCompositeTransform();
		Image newImage = imagesService.applyTransform(transform, oldImage,
				ImagesService.OutputEncoding.PNG);
		byte[] newImageData = newImage.getImageData();

		String imgtype = "image/png";
		this.content = newImageData;
		this.name = name;
		this.contentType = imgtype;
	}

	public byte[] getContent() {
		return content;
	}

	public String getName() {
		return name;
	}

	public String getContentType() {
		return contentType;
	}

}
